package de.hdu.pms.ho.dao;

import org.junit.Test;
import java.util.List;
//import antlr.collections.List; // kollodiert mit dwe java.util.List
import de.hdu.pms.ho.model.Kunde;
import de.hdu.pms.ho.dao.KundeDao;

/**Test class for {@link KundeDao} testing
 * This class will test FindById(), FindAll() and create()
 * @author Hendrik Neumann
 *
 */
public class KundenDaoTest extends AbstractDataAccessTest {


	private KundeDao kundeDao;
	private String tableName = "Kunde";
	
	public void setKundeDao(KundeDao kundeDao) {
		this.kundeDao = kundeDao;
	}
	
	
	/**Test method for testing the method FindById() in the class 
	 * {@link KundeDao}. The test data will deleted after use.
	 * 
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void testFindById() {
		String[] tables = {tableName};
		deleteFromTables(tables);
		kundeDao.create("Hendrik", "Neumann", 123545);
		kundeDao.create("Werner", "Wernersen", 2121212);
		List<Kunde> alleKunden = kundeDao.findAll();
		for (Kunde k : alleKunden) {
			int id = k.getId();
			Kunde found = kundeDao.findById(id);
			assertEquals(k.getName(), found.getName());
		}
		deleteFromTables(tables);
	}
	
	/**Test method for testing the method FindAll() in the
	 * class {@link KundeDao}. See also testFindById()
	 * 
	 */
	@Test
	public void testFindAll() {
		// already tested by testFindById()
		testFindById();
	}
	
	/**Test method for testing the method create() in the class 
	 * {@link KundeDao}. The test data will deleted after use.
	 * 
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void testCreate() {
		String tabellennameKunde = "kunde";
		String[] tables = {tableName};
		deleteFromTables(tables);
		kundeDao.create("Hendrik", "Neumann", 123545);
		int rows = countRowsInTable(tabellennameKunde);
		assertEquals("Die DB muss eine Zeile enthalten", 1, rows);
	}
}
